package day12;

/**
 * @author oldliu
 * @since 1.0
 */
public class Thread3 implements Runnable {
    private String name;
    public Thread3(String n){
        this.name=n;
    }
    @Override
    public void run() {
        for(int i=1;i<=20;i++){
            System.out.println(this.name+" print "+i);
        }
    }

    public static void main(String[] args) {
//        for(int i=1;i<=4;i++){
//            Thread th=new Thread(new Thread3("线程"+i));
//            th.start();
//        }
        Thread th[]=new Thread[4];
        for(int i=1;i<=4;i++){
            th[i-1]=new Thread(new Thread3("线程"+i));
            th[i-1].start();
        }
        for(int i=1;i<=4;i++){
            try {
                th[i-1].join();//主线程等待th
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(Thread.activeCount()+"个活动线程！");
        System.out.println(Thread.currentThread().getName()+" 结束了。。。");
        for (int i = 0; i < th.length; i++) {
            System.out.println(th[i].getName()+"还活着？"+th[i].isAlive());
        }
    }
}
